package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingController
 * @Author fy
 * @Date 2025-05-07  19:52
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 条件分页查询所有护理项目
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation(value = "条件分页查询所有护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> getNursingProject(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return success(nursingProjectPageInfo);
    }

    /**
     * 添加护理项目
     * @param nursingProjectDto
     *
     * @return
     */

    @PostMapping
    @ApiOperation(value = "添加护理项目")
    public ResponseResult addNursingProject(@ApiParam(value = "护理项目信息") @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目")
    public ResponseResult getNursingProjectById(@PathVariable("id") Long id){
        NursingProjectVo listById =nursingProjectService.getNursingProjectById(id);
        return success(listById);

    }

    /**
     * 根据id修改护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "根据id修改护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 根据id删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除护理项目")
    public ResponseResult deleteNursingProject(@PathVariable("id") Long id){
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    /**
     * 根据id修改护理项目状态
     * @param id
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "根据id修改护理项目状态")
    public ResponseResult updateNursingProjectStatus(@PathVariable("id") Long id){
        nursingProjectService.updateStatus(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject(){
        List<NursingProjectVo> allNursingProject = nursingProjectService.getAllNursingProject();
        return success(allNursingProject);
    }

}
